package com.basic.lock;

public class DeadLock {
	
	private static Object lock1 = new Object();
	
	private static Object lock2 = new Object();
	
	public static void main(String[] args) {
		Thread t1 = new Thread(new Runnable() {
			@Override
			public void run() {
				DeadLock deadLock = new DeadLock();
				deadLock.test1();
			}
		});
		
		Thread t2 = new Thread(new Runnable() {
			@Override
			public void run() {
				DeadLock deadLock = new DeadLock();
				deadLock.test2();
			}
		});
		t1.start();
		t2.start();
		Thread.yield();
	}
	
	private void test1(){
		synchronized (lock1) {
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			synchronized (lock2) {
				System.out.println("test1.......");
			}
		}
	}
	
	private void test2(){
		synchronized (lock2) {
			try {
				Thread.sleep(1);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			synchronized (lock1) {
				System.out.println("test2.......");
			}
		}
	}
}
